# -*- coding: utf-8 -*-
'''
Created on Apr 23, 2011

@author: Yang Sun
'''
import sys, xbmc, xbmcaddon
import log

__version__ = '1.0.0'
__addonname__ = "PPTV网络电视"
__addonid__ = "plugin.video.pptv"
__addon__ = xbmcaddon.Addon(id=__addonid__)
__language__ = __addon__.getLocalizedString

__dbg__ = __addon__.getSetting( "debug" ) == "true"


def get_params(param_string):
    param = {}
    paramstring = param_string
    if len(paramstring) >= 2:
        params = param_string
        cleanedparams = params.replace('?', '')
        if (params[len(params) - 1] == '/'):
            params = params[0:len(params) - 2]
        pairsofparams = cleanedparams.split('&')
        param = {}
        for i in range(len(pairsofparams)):
            splitparams = {}
            splitparams = pairsofparams[i].split('=')
            if (len(splitparams)) == 2:
                param[splitparams[0]] = splitparams[1]   
    return param

if(__name__ == '__main__'):
    log.info(repr(sys.argv)) 
    import pptvgui
    
    params = get_params(sys.argv[2])
       
    gui = pptvgui.PPTVUI()
    gui.listMenu(params)    

''' Test Code
pptv = PPTV()
prog = pptv.getProgram()[0]
server = pptv.getServer(prog)
drag_info = pptv.getDragUrl(prog)
urls = pptv.getVideoUrl(prog, server, drag_info)

playlist=xbmc.PlayList(1)
playlist.clear()
index = 0
while index < len(urls):
    playlist.add(urls[index])
    index += 1            

xbmc.Player().play(playlist)        
'''

